﻿
Ext.define("app.main.home.Follower",
{
    extend: 'Ext.panel.Panel',
    // title: '待办事项',
    tbar: [],
    initComponent: function () {
        var me = this;
        me.items = [
            me.getDataView()
        ];

        me.tbar = ["<b>关注的问题</b>", "->",
            {
                text: '取消关注',
                glyph: 0xf00d,
                handler: function ()
                {
                    var sel = me.getDataView().getSelectionModel().getSelection();
                    if (sel == null || sel.length == 0)
                    {
                        Ext.Msg.alert('系统提示', '请选择一条任务');
                        return false;
                    }
                    var record = sel[0];
                    Ext.Msg.confirm('系统提示', '确定要取消关注吗？',
                    function (btn) {
                        if (btn == 'yes') {
                            App.AjaxDelete('/api/services/app/projectTask/RemoveFollower?followerId=' + record.data.followerId, function () {
                                me.store.load();
                            });
                        }
                    });
                }
            },
            {
                text: '刷新',
                glyph: 0xf021, handler: function () { me.store.load(); }
            }];
        me.callParent(arguments);
    },
    getDataView: function () {
        var me = this;
        if (!this.dataView) {
            me.store = Ext.create("app.ux.PrmStore", { url: '/api/services/app/projectTask/GetMyFollower' });

            this.dataView = new Ext.view.View({
                store: me.store,
                tpl: [
                    '<tpl for=".">',
                        '<div style="margin:5px">',
                            //'<a href="javascript:void(0)">({ProjectName}){title}</a>',
                            '(<span style="color:red">{projectName}</span>){title}<span style="color:red">({planFinshTime}){members}</span>',
                        '</div>',
                    '</tpl>'
                ],
                multiSelect: true,
                autoHeight: true,
                trackOver: true,
                itemSelector: 'div.thumb-wrap',
                overItemCls: 'x-item-over',
                itemSelector: 'div',
                emptyText: '暂无待办',
                prepareData: function (data) {
                    return data;
                },
                listeners: {
                    itemclick: 'onWorkOpen'
                }
            });
        }
        return this.dataView;
    },
    doTask: function () {
        var me = this;

        var task = {
            run: function () {
                me.store.load();
            },
            interval: 5 * 60 * 1000
        }
        Ext.util.TaskManager.start(task);
    },
    listeners: {
        afterrender: function (win) {
            win.doTask();
        }
    }
});